<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车辆中文品牌">
              <a-input
                placeholder="请输入车辆中文品牌"
                @blur="nameBlur"
                v-decorator="['name', { rules: [{ required: true, message: '请输入车辆中文品牌' }] }]"
              />
            </a-form-item>
          </a-col>
          <a-col :xs="24" :sm="12">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="车辆车型">
              <a-input
                placeholder="请输入车辆车型"
                v-decorator="['carModel', { rules: [{ required: true, message: '请输入车辆车型' }] }]"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction, getAction } from '@/api/manage'
import pick from 'lodash.pick'
import moment from 'moment'

export default {
  name: 'BrandModel',
  data() {
    return {
      title: '交易信息',
      visible: false,
      model: {},
      saleSource: [],
      SaleInfosLike: [],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 },
      },

      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/sale/cxmSaleBaseInfo/addBaseInfo',
        edit: '/sale/cxmSaleBaseInfo/editBaseInfo',
      },
      showDing: false,
      showEnterpriseUscc: false,
      carModel: '',
      brandId: ''
    }
  },
  created() {
  },
  methods: {
    changeDepositNotes(val) {
      if (val == '不可退') {
        this.showDing = true
      } else {
        this.showDing = false
      }
    },
    add() {
      const that = this;
      that.edit({})
    },
    edit(record) {
      console.log(record);
      this.form.resetFields()
      this.model = Object.assign({}, record)
      console.log(this.model);
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue({
          name: this.model.parentName,
          carModel: this.model.carModel
        })
      })

    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = '';
          this.carModel = this.form.getFieldValue('carModel');
          if (!this.model.id) {
            httpurl += this.url.add
          } else {
            httpurl += this.url.edit
          }
          httpAction(httpurl, { name: this.carModel, dataType: 8, parentId: this.brandId }, 'post')
            .then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.$emit('ok')
              } else {
                that.$message.warning(res.message)
              }
            })
            .finally(() => {
              that.confirmLoading = false
              that.close()
            })
        }
      })
    },
    handleCancel() {
      this.close()
    },
    nameBlur(e) {
      console.log(e.target.value);
      const that = this;
      httpAction(this.url.add, { name: e.target.value, dataType: 1 }, 'post').then((res) => {
        if (res.success) {
          console.log(res.result.id);
          that.brandId = res.result.id;
        }
      })
    }
  },
}
</script>

<style lang="less" scoped>
</style>